from transformers import pipeline

# 1. 加载微调后的模型和分词器
model_path = "../final_model"  # 你在 Trainer 保存的目录
clf = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)

# 2. 输入你想预测的影评
test_reviews = [
    "I absolutely loved this movie! The acting was fantastic and the plot was gripping.",
    "Terrible. I wasted two hours of my life watching this mess.",
    "It's okay, not the best, not the worst."
]

# 3. 执行预测
results = clf(test_reviews, truncation=True, max_length=256)

# 4. 输出结果
for review, res in zip(test_reviews, results):
    print(f"Review: {review}")
    print(f"Prediction: {res['label']} (score={res['score']:.4f})\n")